//
//  CurrentTableViewCell.swift
//  koolcar
//
//  Created by kuaimaxiansheng on 2023/9/19.
//

import UIKit

class CurrentTableViewCell: UITableViewCell {
    var carImageView: UIImageView!
    var titleLab: UILabel!
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.backgroundColor = .white
        self.clipsToBounds = true
        self.selectionStyle = .none
        self.initUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func initUI(){
        
        self.carImageView = UIImageView(frame: .zero)
        self.carImageView.layer.cornerRadius = 8
        self.carImageView.layer.masksToBounds = true
        self.carImageView.backgroundColor = .white
        self.contentView.addSubview(self.carImageView)
        
        self.titleLab = UILabel(frame: CGRect(x: 0, y: self.carImageView.frame.maxY + 6, width: self.frame.size.width, height: 40))
        self.titleLab.textColor = Theme.titleLabColor
        self.titleLab.font = UIFont.init(name: Theme.PingFangSCMedium, size: 14)
        self.titleLab.numberOfLines = 2
        self.contentView.addSubview(self.titleLab)
        
        self.titleLab.text = "香港车主谈“港车北上”:期待已久，方便好多"
        
        self.carImageView.snp.makeConstraints { make in
            make.top.equalTo(0)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.height.equalTo(195)
        }
        
        self.titleLab.snp.makeConstraints { make in
            make.top.equalTo(self.carImageView.snp.bottom).offset(6)
            make.left.equalTo(14)
            make.right.equalTo(-14)
            make.height.equalTo(40)
            make.bottom.equalTo(-20)
        }
        
    }
    
    //setModel
    func setModel(model: ArticleListModel){
        self.carImageView.sd_setImage(with: URL(string: model.imageUrl ?? ""))
        self.titleLab.text = model.title ?? ""
    }
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
